package com.kfm.servlet.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cookie/create")
public class CookieCreateServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 创建 cookie, 默认值： path = 当前项目名 + 当前路径(前一级)， 过期时间： 关闭浏览器
        Cookie cookie = new Cookie("name", "kfm");

        // 响应 cookie
        resp.addCookie(cookie);
    }
}
